Skip to content


ardupilot  None  ros2  dds  micro ros  xrce  lua  sitl  scripts  plugin  gazebo  garden  SITL  debug  rangefinder  pymavlink  mavros  distance sensor  system_time  timesync  ardurover  script  cheat sheet  mavlink  wireshark  mavproxy  mission planner  cmake  gtest  ctest  101  cpp  c++  format  fmt  smart pointers  multithreading  spdlog  cyclonedds  eprosima  fastdds  aptly  apt  repository  repo  local  mirror  encryption  pgp  docker  arm  container  state  networking  network  nvidia  python  app  devcontainer  gui  tutorial  tips  volume  mount  compose  multi-stage  stage  docker compose  microsoft  dotnet  .net  c#  vscode  git  bundle  backup  submodules  github  hooks  pre-commit  marpit  presentation  marp  markdown  mermaid  mkdocs  qml  qt  qtcreator  video  ffmpeg  gstreamer  cheat-sheet  sdp  opencv  appsrc  appsink  acceleration  va-api  intel  v4l2loopback  pipe  compositor  alpha  shmsink  shmsrc  intersink  intersrc  tee  queue  udp  stream  gst  binding  gi  kml  geo  gis  spatial  gdal  ogr  raster  vector  qgc  qgroundcontrol  snippets  cheat Sheet  asyncio  event  future  thread  task  can  canbus  click  cli  cupy  numpy  gpu  dataclass  slots  dev container  fastapi  rest  uvicorn  deb  debian  package  setup  stdeb  project  jupyter  widgets  interactive  plot  matplotlib  ipywidgets  3d  subplot  open3d  point cloud  template  black  isort  templates  cookiecutter  docs  project document  docstrings  flake8  linter  git-hook  mypy  unittest  pytest  pylint  from a-z  fixture  scope  logging  pytest.ini  mock  parameterize  enum  flag  iterator  generator  yaml  yml  logging config  tuple  namedtuple  typing  annotation  generic  literal  protocol  self  typed dict  typevar  pyzmq  zmq  msgpack  slam  cartographer  slam_toolbox  action  namespace  remap  control2  demo  diff-drive  ignition  ros2_control  effort  velocity  gdb  qos  tag  plugins  msg  node  zero-copy  shm  rmw  discovery  zenoh  bridge  zenoh-plugin-ros2dds  algorithm  calibration  diff  pid  dev  colcon  colcon_cd  clean  settings  behavior  py_trees  bt  behavior_trees  blackboard  visualization  debugging  diagnostic  DiagnosticTask  diagnostics  tutorials  math  apm  rat_runtime_monitor  bag  rosbag  rosbags  tools  ros  smach  state machine  web  rosbridge  vue  profile  gazebo-classic  launch  spawn  model  cook  camera  sensors  gps  imu  ray  gazebo_ros_ray_sensor  lidar  ultrsonic  range  ultrasonic  gazebo classic  wrench  gazebo_ros_state  gz  sdf  world  vscode tips  gazebogz-sim-joint-position-controller-system  simulation  ros_gz_bridge  ign  xacro  diff_drive  odom  odometry  joint_state  argument  OpaqueFunction  DeclareLaunchArgument  LaunchConfiguration  tmux  tmuxp  nav  nav2  turtlebot  perception  test  rclpy  goal abort  cancel goal  action client  action server  custom messages  executor  MultiThreadedExecutor  SingleThreadedExecutor  lifecycle  parameter  param  dynamic-reconfigure  get  global server  persist_parameter  service  client  setup.py  package.xml  parameters  custom  msgs  executers  pub  sub  rqt  rviz  rviz2  pose  marker  tf2  local_setup  rosdep  package manager  project settings  vcstool  urdf  robot_state_publisher  urdf_to_graphiz  joint  link  rust  deep learning  ai  beginner  regression  reinforcement learning  q learning  gym  gymnasium  deepsort  onnx  inference  build  source  wheel  cuda  vision  siam-mask  tracking  segmentation  yolo  ultralytics  yolov8  jetson  tensorrt  cross-compiler  esp32  nano  i2c  adafruit  arduino  sensor  mb1202  uart  serial  tfmini  rpi  raspberry pi  arducam  teensy  microros  micro python  embedded  pymakr  config  material  workshope  texture  joints  loop device  rootfs  zah  linux  rm  ubuntu  sudo  sudoers  nopasswd  visudo  shell  udev  key  gpg  sign  commands  update-alternative  dpkg  ip  ss  netstat  snap  deploy  ssh  systemd  socat  tc  mtu  select  robotics  path planning  trajectory  speed  pcl  kalman_filter  kalman  filter  control  code  extensions  remote  json  schema  yocto  poky  qemu  projects  courses to follow  matrix  graphics  rotation  2d  course  drone  quad  uav  design  geometric control  se3  so3  joint_states  JointState  Header  vrx  buoyancy 

Docker Python application#

Using pysimplegui to build simple python GUI application

Using Docker as production, development and test environment Using VSCode devcontainer as development setup

Dockerfile#

Build from four stage: 1. python_base: base on ubuntu 22.04 that add user and install python 2. deploy: Add python application dependencies install by apt and pip (without the application it self) 3. prod: Install the application using whl build by development 4. development: Add all packages need by the development and build system


Helper scripts#

Deploy#

Check that the application can installed and run

  • Deploy container include all package needed by the application for running (apt and pip)
  • Run docker container with user permission and x11 support
  • Create share from <project>/dist folder to install the application on docker container
  • Install run by the user from /dist folder using pip
run_deploy_container.sh
docker run -it --rm \
    --name py_deploy \
    --hostname deploy \
    -u=$(id -u $USER):$(id -g $USER) \
    -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix:rw \
    -v $(pwd)/dist:/dist \
    py_gui_demo:deploy \
    /bin/bash

Prod#

Create docker container that run the application

  • Base on prod stage that install all application package dependencies
  • Get the application version to build from outside (vscode task, command line)
  • Set entrypoint

PATH

The application entry point installed in <user home>/.local/bin

The docker add this environment variable with ENV command

ENV PATH=${PATH}:/home/user/.local/bin

production stage
# ###################      production     #############################

FROM deploy as prod
ARG APP_VER=0
USER user
WORKDIR /home/user
RUN echo ${APP_VER}
COPY ./dist/py_gui_demo-${APP_VER}-py3-none-any.whl /tmp
RUN pip install /tmp/py_gui_demo-${APP_VER}-py3-none-any.whl
ENTRYPOINT ["my_app"]
run_prod_container.sh
docker run -it --rm \
    --name py_prod \
    --hostname prod \
    -u=$(id -u $USER):$(id -g $USER) \
    -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix:rw \
    py_gui_demo:prod

Base#

Create docker container that include only the ubuntu base with python and pip install without all application package dependencies, use to check whl and deb installation

  • Container with user context and x11 support
  • Share dist and deb_dist folder from host
run_base_container.sh
docker run -it --rm \
    --name py_base \
    --hostname base \
    -u=$(id -u $USER):$(id -g $USER) \
    -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix:rw \
    -v $(pwd)/dist:/dist \
    -v $(pwd)/deb_dist:/deb_dist \
    py_gui_demo:base \
    /bin/bash

VSCode#

devcontainer#

tasks#

  • Add task build each dockerfile stage
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build deploy container",
            "type": "shell",
            "command": "docker build --target deploy -t ${workspaceFolderBasename}:deploy -f .devcontainer/Dockerfile .",
            "problemMatcher": []
        },
        {
            "label": "build base container",
            "type": "shell",
            "command": "docker build --target python_base -t ${workspaceFolderBasename}:base -f .devcontainer/Dockerfile .",
            "problemMatcher": []
        },
        {
            "label": "build prod container",
            "type": "shell",
            "command": "docker build --target prod -t ${workspaceFolderBasename}:prod -f .devcontainer/Dockerfile --build-arg APP_VER=${input:app_version} .",
            "problemMatcher": []
        }

    ],
    "inputs": [
        {
            "id": "app_version",
            "description": "app_version",
            "options": ["0.0.1", "0.0.2"],
            "type": "pickString"
        },
    ]
}